<?php
/**
 * Template Name: Book
 */
get_header(); ?>

<div class="container">
    <h1>Confirm Booking Details</h1>

    <div class="row-fluid">
        <div class="span8">
            <div class="card grey clearfix">

                <?

                $slotid = $_POST['slotid'];
                $pitchid = $_POST['pitchid'];
                $venueid = $_POST['venueid'];
                $start_time = $_POST['start-time'];
                $end_time = $_POST['end-time'];
                $day = $_POST['day'];
                $date = $_POST['date'];

                //echo ;

                //echo '<pre>';
                //var_dump(get_post_meta($slotid, 'pitch', true));
                //echo '</pre>';
                ?>

                <h3><? echo  $day . ', ' . $start_time . ' - ' . $end_time . ' | ' . get_field('pid', $pitchid) ?></h3>

                <h3><? echo get_field('name', $venueid) ?></h3>

                <table class="table table-bordered table-condensed table-striped">
                    <tbody>
                    <tr>
                        <td><h3>Where</h3></td>
                        <td><? echo get_the_title($pitchid) ?> <br></td>
                    </tr>
                    <tr>
                        <td><h3>Address</h3></td>
                        <td><? the_field('address', $venueid)  ?></td>
                    </tr>
                    <tr>
                        <td><h3>When</h3></td>
                        <td><? echo $day . ', ' . $date, ' from ' . $start_time . ' to ' . $end_time  ?></td>
                    </tr>
                    <tr>
                        <td><h3>Who</h3></td>
                        <td><? echo 'Booked by ' . get_field('first_name', 'user_' . get_user_id()) . ' ' . get_field('last_name', 'user_' . get_user_id());  ?></td>
                    </tr>
                    <tr>
                        <td><h3>Pitch</h3></td>
                        <td><? echo get_field('size', $pitchid) . ', ' . get_field('surface', $pitchid) . ' surface' ?></td>
                    </tr>
                    <tr>
                        <td><h3>Price</h3></td>
                        <td><? echo '£'.get_field('price', $slotid); ?></td>
                    </tr>
                    </tbody>
                </table>

                <hr>
                <div class="alert alert-info" style="display: none">
                </div>

                <form id="book-form" style="margin:0" method="post" action="/book/">
                    <input type="hidden" name="slotid" value="<? echo $slotid ?>"/>
                    <input type="hidden" name="pitchid" value="<? echo $pitchid ?>"/>
                    <input type="hidden" name="venueid" value="<? echo $venueid ?>"/>
                    <input type="hidden" name="start-time" value="<? echo $start_time ?>"/>
                    <input type="hidden" name="end-time" value="<? echo $end_time ?>"/>
                    <input type="hidden" name="day" value="<? echo $day ?>"/>
                    <input type="hidden" name="date" value="<? echo $date ?>"/>
                    <input type="hidden" name="userid" value="<? echo get_user_id() ?>"/>
                    <input type="hidden" name="userfirst"
                           value="<? echo get_field('first_name', 'user_' . get_user_id()) ?>"/>
                    <input type="hidden" name="userlast"
                           value="<? echo get_field('last_name', 'user_' . get_user_id()) ?>"/>
                    <input type="hidden" name="action" value="book"/>

                    <button type="submit" class="btn btn-small btn-primary">Book now with PitchWise! &raquo;</button>
                </form>

            </div>
        </div>
        <div class="span4">
            <div class="card grey">
                <? $image = wp_get_attachment_image_src(get_field('image_1', $pitchid), 'pitch-main');
                if (get_field('image_1', $pitchid)) {
                    echo '<img style="margin-bottom:15px; border-radius:3px;" src="' . $image[0] . '"/>';
                } else {
                    echo '<img style="margin-bottom:15px; border-radius:3px;" src="http://pitchwise.co.uk/wp-content/uploads/2012/11/PitchWise-Logo-Light-658x300.png"/>';
                } ?>
            </div>
        </div>
    </div>
</div>


<?php get_footer(); ?>

<script src="<?php echo get_template_directory_uri(); ?>/js/PITCHWISE.book.js"></script>

<script>
    $(function () {
        var options = {
            'slotID':'<? echo $slotid ?>',
            'pitchID':'<? echo $pitchid ?>',
            'venueID':'<? echo $venueid ?>',
            'startTime':'<? echo $start_time ?>',
            'endTime':'<? echo $end_time ?>',
            'day':'<? echo $day ?>',
            'date':'<? echo $date ?>'
        };

        var book = new PITCHWISE.book(options);
    });
</script>